import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;

/**
 * Created by codeczx on 2017/7/18.
 */
public class ServerThread implements Runnable{

    private Socket client = null;

    public ServerThread(Socket client){
        this.client = client;
    }

    @Override
    public void run() {
        try {
            PrintStream clientOut = new PrintStream(client.getOutputStream());
            BufferedReader clientIn = new BufferedReader(new InputStreamReader(client.getInputStream()));
            boolean flag = true;
            while(flag){
                String str = clientIn.readLine();
                if(str == null ||"".equals(str)){
                    flag = false;
                }else{
                    if("bye".equals(str)){
                        flag = false;
                    }else{
                        clientOut.println("server:"+str);
                    }
                }
            }
            clientOut.close();
            clientIn.close();
            client.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
